package cn.wjh.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.wjh.common.utils.SecurityUtils;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.wjh.common.annotation.Log;
import cn.wjh.common.core.controller.BaseController;
import cn.wjh.common.core.domain.AjaxResult;
import cn.wjh.common.enums.BusinessType;
import cn.wjh.business.domain.LanguageGroup;
import cn.wjh.business.service.ILanguageGroupService;
import cn.wjh.common.utils.poi.ExcelUtil;
import cn.wjh.common.core.page.TableDataInfo;

/**
 * 语言编组Controller
 *
 * @author jiraWu
 * @date 2023-12-27
 */
@RestController
@RequestMapping("/business/LanguageGroup")
public class LanguageGroupController extends BaseController {
    @Resource
    private ILanguageGroupService languageGroupService;

    /**
     * 查询语言编组列表
     */
//    @PreAuthorize("@ss.hasPermi('business:LanguageGroup:list')")
    @GetMapping("/list")
    @Cacheable(value = "languageGroupListCache", keyGenerator = "cacheKeyGenerator")
    public TableDataInfo list(LanguageGroup languageGroup) {
        startPage();
        List<LanguageGroup> list = languageGroupService.selectLanguageGroupList(languageGroup);
        return getDataTable(list);
    }

    @GetMapping("/myList")
    public TableDataInfo myList(LanguageGroup languageGroup) {
        startPage();
        languageGroup.setUserId(SecurityUtils.getUserId());
        List<LanguageGroup> list = languageGroupService.selectLanguageGroupList(languageGroup);
        return getDataTable(list);
    }

    /**
     * 导出语言编组列表
     */
//    @PreAuthorize("@ss.hasPermi('business:LanguageGroup:export')")
    @Log(title = "语言编组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LanguageGroup languageGroup) {
        List<LanguageGroup> list = languageGroupService.selectLanguageGroupList(languageGroup);
        ExcelUtil<LanguageGroup> util = new ExcelUtil<LanguageGroup>(LanguageGroup.class);
        util.exportExcel(response, list, "语言编组数据");
    }

    /**
     * 获取语言编组详细信息
     */
//    @PreAuthorize("@ss.hasPermi('business:LanguageGroup:query')")
    @GetMapping(value = "/{languageGroupId}")
    @Cacheable(value = "languageGroupListCache", keyGenerator = "cacheKeyGenerator")
    public AjaxResult getInfo(@PathVariable("languageGroupId") Long languageGroupId) {
        return success(languageGroupService.selectLanguageGroupByLanguageGroupId(languageGroupId));
    }

    /**
     * 新增语言编组
     */
//    @PreAuthorize("@ss.hasPermi('business:LanguageGroup:add')")
    @Log(title = "语言编组", businessType = BusinessType.INSERT)
    @PostMapping
    @CacheEvict(value = "languageGroupListCache", allEntries = true)
    public AjaxResult add(@RequestBody LanguageGroup languageGroup) {
        languageGroup.setUserId(SecurityUtils.getUserId());
        languageGroup.setCreateBy(SecurityUtils.getUsername());
        return toAjax(languageGroupService.insertLanguageGroup(languageGroup));
    }

    /**
     * 修改语言编组
     */
//    @PreAuthorize("@ss.hasPermi('business:LanguageGroup:edit')")
    @Log(title = "语言编组", businessType = BusinessType.UPDATE)
    @PutMapping
    @CacheEvict(value = "languageGroupListCache", allEntries = true)
    public AjaxResult edit(@RequestBody LanguageGroup languageGroup) {
        return toAjax(languageGroupService.updateLanguageGroup(languageGroup));
    }

    /**
     * 删除语言编组
     */
//    @PreAuthorize("@ss.hasPermi('business:LanguageGroup:remove')")
    @Log(title = "语言编组", businessType = BusinessType.DELETE)
    @DeleteMapping("/{languageGroupIds}")
    @CacheEvict(value = "languageGroupListCache", allEntries = true)
    public AjaxResult remove(@PathVariable Long[] languageGroupIds) {
        return toAjax(languageGroupService.deleteLanguageGroupByLanguageGroupIds(languageGroupIds));
    }
}
